//
//  CustomNewsShowView.m
//  AmountBody
//
//  Created by smm on 2018/1/17.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

#import "CustomNewsShowView.h"

@implementation CustomNewsShowView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
    }
    return self;
}
-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setupViews];
    }
    return self;
}
-(instancetype)init
{
    self = [super init];
    if (self) {
        [self setupViews];
    }
    return self;
}
-(void)setupViews
{
    _leftLabel = [[UILabel alloc]init];
    [self addSubview:_leftLabel];
    _rightLabel = [[UILabel alloc]init];
    [self addSubview:_rightLabel];
    _lineImage = [[UIImageView alloc]init];
    [self addSubview:_lineImage];
    
}

-(void)loadUIForShowView
{
    [self loadData];
    switch (_showType) {
        case ShowTypeForLeft:
        {
            [self loadUIForLeft];
        }
            break;
        case ShowTypeForLeftAndRight:
        {
             [self loadUIForLeftAndRight];
        }
            break;
        
        default:
            break;
    }
}
-(void)loadData
{
    CGFloat jianGe = 8;
    CGFloat jianGeH = 10;
    NSString * needStr = [NSString stringWithFormat:@"%@%@",_l_model.name,_l_model.value];
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:needStr];
    
    // 设置字体和设置字体的范围
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:12.0f]
                    range:NSMakeRange(0, needStr.length)];
    // 添加文字颜色
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:QianZi_color
                    range:NSMakeRange(0, needStr.length)];
    // 添加文字颜色
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:ZhongZi_Color
                    range:NSMakeRange(_l_model.name.length, _l_model.value.length)];
    // 设置字体和设置字体的范围
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:13.0f]
                    range:NSMakeRange(_l_model.name.length, _l_model.value.length)];
    
    _leftLabel.attributedText = attrStr;
    _leftLabel.numberOfLines = 0;
    _lineImage.image = [UIImage imageNamed:@"quline"];
    needStr = [NSString stringWithFormat:@"%@%@",_r_model.name,_r_model.value];
    attrStr = [[NSMutableAttributedString alloc] initWithString:needStr];
    
    // 设置字体和设置字体的范围
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:12.0f]
                    range:NSMakeRange(0, needStr.length)];
    // 添加文字颜色
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:QianZi_color
                    range:NSMakeRange(0, needStr.length)];
    // 添加文字颜色
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:ZhongZi_Color
                    range:NSMakeRange(_r_model.name.length, _r_model.value.length)];
    // 设置字体和设置字体的范围
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:13.0f]
                    range:NSMakeRange(_r_model.name.length, _r_model.value.length)];
    
    
    _rightLabel.hidden = NO;
    _rightLabel.attributedText = attrStr;
    _rightLabel.numberOfLines = 0;
    
    [_lineImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.right.equalTo(self);
        make.top.equalTo(_leftLabel.mas_bottom);
        make.height.equalTo(@(1));
        //        make.bottom.equalTo(self);
    }];
}
-(void)loadUIForLeft
{
    _rightLabel.hidden = YES;
    CGFloat jianGe = 8;
    CGFloat jianGeH = 10;
    [_leftLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.right.equalTo(self);
        make.top.equalTo(self);
        make.bottom.equalTo(self).offset(-1);
    }];
    
}

-(void)loadUIForLeftAndRight
{
    _rightLabel.hidden = NO;
    CGFloat jianGe = 8;
    CGFloat jianGeH = 10;
    [_leftLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.width.equalTo(self).multipliedBy(0.5).offset(-jianGe);
        make.top.equalTo(self);
        make.bottom.equalTo(self).offset(-1);
  
    }];
    
    [_rightLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-jianGe);
        make.width.equalTo(self).multipliedBy(0.5).offset(-jianGe);
        make.top.equalTo(self);
        make.bottom.equalTo(self).offset(-1);
    }];
   
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
